#两两交换链表中的节点
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
from typing import Optional
from typing import ListNode
class Solution:
    def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]:
        dummy_head=ListNode(next=head)
        current=dummy_head

        while current.next!=None and current.next.next!=None:
            temp1=current.next
            temp2=current.next.next.next

            current.next=current.next.next   #步骤一
            current.next.next=temp1    #步骤二
            temp1.next=temp2                #步骤三

            current=current.next.next

        return dummy_head.next